package controller;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.TreeSet;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.swing.text.Utilities;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import dto.AdminDTO;
import dto.CompanyDTO;
import dto.ListCompanyPageDTO;
import dto.ListMemberPageDTO;
import dto.ListSalePageDTO;
import dto.MemberDTO;
import dto.PagingDTO;



import service.MemberService;
@Controller
public class MemberController {
	private MemberService service;
	public MemberController(MemberService service){
		this.service = service;
	}
 //일반 회원 로그인
	@RequestMapping("memberLogin.do")
	public ModelAndView login(String id, String password, HttpSession session,HttpServletRequest request){
		String choiceMember = request.getParameter("choiceMember");
		
		ModelAndView mv = null;
		MemberDTO mdto = null;
		CompanyDTO cdto = null;
		AdminDTO adto = null;
		 	
		try {
			if(choiceMember.equals("member")){
				mdto = service.getMemberById(id);
				
			}else if(choiceMember.equals("company")){
				cdto = service.getCompanyById(id);
				
			}else if(choiceMember.equals("admin")){
				adto = service.getAdminById(id);
			}
			
		
			if(mdto!=null && mdto.getIs_validate().equals("O")){//id가 있는 경우
				if(mdto.getPassword().equals(password)){//id와 password가 맞는 경우
				
					session.setAttribute("memberDTO", mdto);
					mv = new ModelAndView("mainPage.do");
				}else{//id가 맞고 비밀번호가 틀린경우
					mv = new ModelAndView("mainPage.do","error_message",password+"는 없는 비밀번호입니다.");
				}
			}else if(cdto!=null && cdto.getIs_validate().equals("O")){
				if(cdto.getPassword().equals(password)){//id와 password가 맞는 경우
				
					session.setAttribute("companyDTO", cdto);
					mv = new ModelAndView("mainPage.do");
				}else{//id가 맞고 비밀번호가 틀린경우
					mv = new ModelAndView("mainPage.do","error_message",password+"는 없는 비밀번호입니다.");
				}
			}else if(adto!=null){
				if(adto.getPassword().equals(password)){//id와 password가 맞는 경우
				 
					session.setAttribute("adminDTO", adto);
					mv = new ModelAndView("mainPage.do");
				}else{//id가 맞고 비밀번호가 틀린경우
					mv = new ModelAndView("mainPage.do","error_message",password+"는 없는 비밀번호입니다.");
				}
			}
			else{//id와 비밀번호가 틀린경우
				mv = new ModelAndView("mainPage.do","error_message",id+"는 로그인 할수 없는 아이디입니다.");
			}
		} catch (SQLException e) {
			e.printStackTrace();
			mv = new ModelAndView("error.do","error_message",e.getMessage());
		}
		return mv;
	}
	//일반회원 로그아웃
	@RequestMapping("memberLogout.do")
	public ModelAndView logout(HttpSession session){
		ModelAndView mv = null;
		MemberDTO mdto = (MemberDTO) session.getAttribute("memberDTO");
		CompanyDTO cdto = (CompanyDTO) session.getAttribute("companyDTO");
		AdminDTO adto = (AdminDTO) session.getAttribute("adminDTO");
		if(mdto!=null || cdto!=null||adto!=null ){
			 
			mv = new ModelAndView("mainPage.do");
			session.invalidate();
		}else{
			mv = new ModelAndView("mainPage.do","error_message","로그인 후 이용바랍니다.");
		}
		return mv;
	}
	//회원 정보보기
	@RequestMapping("memberInfo.do")
	public ModelAndView getLoginMemberInfo(HttpSession session){
	
		ModelAndView mv = null;
		MemberDTO mdto = (MemberDTO) session.getAttribute("memberDTO");
		CompanyDTO cdto = (CompanyDTO) session.getAttribute("companyDTO");
		AdminDTO adto = (AdminDTO) session.getAttribute("adminDTO");
		if(mdto!=null || cdto!=null||adto!=null ){
			mv = new ModelAndView("memberInfoTiles.do");
		}else{
			mv = new ModelAndView("mainPage.do","error_message","로그인 후 이용바랍니다.");
		}
		return mv;
	}
	//회원탈퇴
	@RequestMapping("removeMember.do")
	public ModelAndView removeMember(HttpSession session){
		 
		ModelAndView mv = null;
		MemberDTO mdto = (MemberDTO) session.getAttribute("memberDTO");
		CompanyDTO cdto = (CompanyDTO) session.getAttribute("companyDTO");
		AdminDTO adto = (AdminDTO) session.getAttribute("adminDTO");
		if(mdto==null && cdto==null&&adto==null ){
			mv = new ModelAndView("mainPage.do","error_message","로그인 후 회원 탈퇴 이용바랍니다.");
		}else{
			try {
				if(mdto!=null){
					service.removeMemberByid(mdto.getId());
				}else if(cdto!=null){
					service.removeCompanyByid(cdto.getId());
				}else if(adto!=null){
					service.removeAdminByid(adto.getId());
				}
				mv = new ModelAndView("mainPage.do");
				//세션 소멸시키기
				session.invalidate();
			} catch (SQLException e) {
			
				e.printStackTrace();
			}
		
		}
		return mv;
	}
	//동으로 주소검색
	@RequestMapping("addressSearch.do")
	public ModelAndView addressSearch(HttpServletRequest request){
		ModelAndView mv = null;
		try{
			String dong = request.getParameter("dong");
			ArrayList list = service.addressSearch(dong);
			return new ModelAndView("/jsp/member/address_popup.jsp","list",list);
		}catch(Exception e){
			e.printStackTrace();
			mv = new ModelAndView("error.do","error_message",e.getMessage());
		}	
		return mv;
	}
	//기업회원가입
	@RequestMapping("registerCompany.do")
	public ModelAndView registerCompany(HttpServletRequest request, CompanyDTO cdto){
		String phone1 = request.getParameter("phone1");
		String phone2 = request.getParameter("phone2");
		String phone3 = request.getParameter("phone3");
		String phone = phone1+phone2+phone3;
		ModelAndView mv = null;
	
		cdto.setPhone(phone);
		cdto.setCredit("0");
		cdto.setMileage(1000);
		cdto.setIs_validate("O");
		String nowTime = util.Utilities.getNow();
		cdto.setRegister_date(nowTime);
		
		service.registerCompany(cdto);
		mv = new ModelAndView("memberCompanyResultTiles.do","companyDTO",cdto);
	
		return mv;
	}
	//회원가입
	@RequestMapping("registerMember.do")
	public ModelAndView registerMember(HttpServletRequest request, MemberDTO mdto){
		
		String phone1 = request.getParameter("phone1");
		 
		String phone2 = request.getParameter("phone2");
		String phone3 = request.getParameter("phone3");
		String phone = phone1+phone2+phone3;
		
		mdto.setPhone(phone);
		mdto.setCredit("일반");
		mdto.setMileage(1000);
		mdto.setIs_validate("O");
		String nowTime = util.Utilities.getNow();
		mdto.setRegister_date(nowTime);
		
		service.registerMember(mdto);
		
		
		return new ModelAndView("memberRegisterResultTiles.do","memberDTO",mdto);
	}
	//가입폼
	@RequestMapping("registerForm.do")
	public ModelAndView memberRegisterIndex(HttpServletRequest request){
		
		String choiceMember = request.getParameter("choiceMember");
		
		ModelAndView mv = null;
		if(choiceMember.equals("member")){
			mv = new ModelAndView("memberRegisterFormTiles.do");
		}else if(choiceMember.equals("company")){
			mv = new ModelAndView("companyRegisterFormTiles.do");
		}
		return mv;
	}
	//ID중복조회
	@RequestMapping("searchMemberById.do")
	public ModelAndView searchMemberById(String id){
	
		MemberDTO mdto;
		String idCheck = "";
		try {
			mdto = service.getMemberById(id);
			 
			if(mdto!=null){
				idCheck = "중복된 id가 있습니다.";
			}else{
				idCheck = "사용가능한 id입니다.";
			}
		
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		return new ModelAndView("jsonView", "idCheck", idCheck);
		//new MemberDTO
	}
	//기업ID중복조회
	@RequestMapping("/searchCompanyById.do")
	public ModelAndView searchCompanyByid(String id){
	
		CompanyDTO cdto;
		String idCheck = "";
		try {
			cdto = service.getCompanyById(id);
			
			if(cdto!=null){
				idCheck = "중복된 id가 있습니다.";
			}else{
				idCheck = "사용가능한 id입니다.";
			}
			
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		return new ModelAndView("jsonView", "idCheck", idCheck);
	}
	//수정폼
	@RequestMapping("modifyForm.do")
	public ModelAndView modifyForm(HttpSession session){
		MemberDTO mdto = (MemberDTO) session.getAttribute("memberDTO");
		AdminDTO adto = (AdminDTO) session.getAttribute("adminDTO");
		CompanyDTO cdto = (CompanyDTO) session.getAttribute("companyDTO");
		ModelAndView mv = null;
		
		if(mdto!=null){
			mv = new ModelAndView("modifyMemberForm.do");
		}else if(cdto!=null){
			mv = new ModelAndView("modifyCompanyForm.do");
		}else if(adto!=null){
			mv = new ModelAndView("modifyAdminForm.do");
		}
		return mv;
	}
	//회원수정
	@RequestMapping("modifyMember.do")
	public ModelAndView modifyMember(HttpSession session,HttpServletRequest request, MemberDTO updateMdto){
		MemberDTO mdto = (MemberDTO) session.getAttribute("memberDTO");
		ModelAndView mv = null;
		String nowTime = util.Utilities.getNow();
		updateMdto.setUpdate_date(nowTime);
		updateMdto.setId(mdto.getId());
		updateMdto.setMileage(mdto.getMileage());
		updateMdto.setCredit(mdto.getCredit());
		updateMdto.setIs_validate(mdto.getIs_validate());
		updateMdto.setRegister_date(mdto.getRegister_date());
		
		String phone1 = request.getParameter("phone1");
		String phone2 = request.getParameter("phone2");
		String phone3 = request.getParameter("phone3");
		String phone = phone1+phone2+phone3;
		
		updateMdto.setPhone(phone);
		
		
		service.modifyMember(updateMdto);
	
		session.setAttribute("memberDTO", updateMdto);
		mv = new ModelAndView("modifyMemberTiles.do");
		return mv;
	}
	//기업수정
	@RequestMapping("modifyCompany.do")
	public ModelAndView modifyCompany(HttpSession session,HttpServletRequest request, CompanyDTO modifyCompany){
		CompanyDTO cdto = (CompanyDTO) session.getAttribute("companyDTO");
		ModelAndView mv = null;
		String nowTime = util.Utilities.getNow();
		modifyCompany.setUpdate_date(nowTime);
		modifyCompany.setId(cdto.getId());
		modifyCompany.setMileage(cdto.getMileage());
		modifyCompany.setCredit(cdto.getCredit());
		modifyCompany.setIs_validate(cdto.getIs_validate());
		modifyCompany.setRegister_date(cdto.getRegister_date());
		
		String phone1 = request.getParameter("phone1");
		String phone2 = request.getParameter("phone2");
		String phone3 = request.getParameter("phone3");
		String phone = phone1+phone2+phone3;
		
		modifyCompany.setPhone(phone);
		
	
		service.modifyCompany(modifyCompany);
		
		session.setAttribute("companyDTO", modifyCompany);
		mv = new ModelAndView("modifyMemberTiles.do");
		return mv;
	}
	//관리자 수정
	@RequestMapping("modifyAdmin.do")
	public ModelAndView modifyAdmin(HttpSession session,HttpServletRequest request, AdminDTO modifyAdmin){
		AdminDTO adto = (AdminDTO) session.getAttribute("adminDTO");
		ModelAndView mv = null;
		String nowTime = util.Utilities.getNow();
		 
		modifyAdmin.setId(adto.getId());
		 
		
		String phone1 = request.getParameter("phone1");
		String phone2 = request.getParameter("phone2");
		String phone3 = request.getParameter("phone3");
		String phone = phone1+phone2+phone3;
		
		modifyAdmin.setPhone(phone);
		modifyAdmin.setUpdateDate(nowTime);
	
		service.modifyAdmin(modifyAdmin);
	
		session.setAttribute("adminDTO", modifyAdmin);
		mv = new ModelAndView("modifyMemberTiles.do");
		return mv;
	}
	//관리자모드폼
	@RequestMapping("adminManager.do")
	public ModelAndView adminManager(){
		 
		return new ModelAndView("adminManagerIndexTiles.do");
	}
	//관리자 모드 화면 뿌리기
	@RequestMapping("adminManagerMemberList.do")
	public ModelAndView adminManagerMemberList(HttpServletRequest request){
		String choiceMember = request.getParameter("choiceMember");
		
		 
		ModelAndView mv = null;
	 
		ArrayList<MemberDTO> memberList = new ArrayList<MemberDTO>();
		ArrayList<CompanyDTO> companyList = new ArrayList<CompanyDTO>();
		if(choiceMember.equals("member")){
			memberList =  service.getAllMember();
		
			mv = new ModelAndView("adminManagerTiles.do","getAllMember", memberList);
		 
		}else if(choiceMember.equals("company")){
			companyList =   (ArrayList<CompanyDTO>)service.getAllCompany();
		
			mv = new ModelAndView("adminManagerTiles.do","getAllCompany", companyList);
		 
		}

		return mv;
	}
	//멤버강제탈퇴
	@RequestMapping("adminMemberDelete.do")
	public ModelAndView adminMemberDelete(HttpServletRequest request,String id, String choiceMember){
		
		 
		int page = Integer.parseInt(request.getParameter("page"));
		 
		ModelAndView mv = null;
		ListMemberPageDTO listMemberDTO = null;
		String nowTime = util.Utilities.getNow();
		try {
			MemberDTO mdto = service.getMemberById(id);
			request.setAttribute("choiceMember", choiceMember);
			mdto.setDelete_date(nowTime);
			mdto.setIs_validate("X");
			service.adminMemberDelete(mdto);
			 
			listMemberDTO = service.getMemberListByPage(page);
			 
			mv = new ModelAndView("adminManagerTiles.do","getAllMember", listMemberDTO);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return mv;
	}
	//기업 강제탈퇴
	@RequestMapping("adminCompanyDelete.do")
	public ModelAndView adminCompanyDelete(HttpServletRequest request,String id, String choiceMember){
		 
		int page = Integer.parseInt(request.getParameter("page"));
		ModelAndView mv = null;
		String nowTime = util.Utilities.getNow();
		ListCompanyPageDTO listCompanyDTO = null;
		try {
			CompanyDTO cdto = service.getCompanyById(id);
			request.setAttribute("choiceMember", choiceMember);
			cdto.setDelete_date(nowTime);
			cdto.setIs_validate("X");
			service.adminCompanyDelete(cdto);
			listCompanyDTO = service.getCompanyListByPage(page);
			mv = new ModelAndView("adminManagerTiles.do","getAllCompany", listCompanyDTO);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return mv;
	}
	//회원 탈퇴 취소
	@RequestMapping("adminMemberReceive.do")
	public ModelAndView adminMemberReceive(HttpServletRequest request, String id, String choiceMember){
		 
		int page = Integer.parseInt(request.getParameter("page"));
		ModelAndView mv = null;
		String nowTime = util.Utilities.getNow();
		ListMemberPageDTO listMemberDTO = null;
		try {
			MemberDTO mdto = service.getMemberById(id);
			request.setAttribute("choiceMember", choiceMember);
			mdto.setDelete_date(nowTime);
			mdto.setIs_validate("O");
			service.adminMemberReceive(mdto);
			listMemberDTO = service.getMemberListByPage(page);
			mv = new ModelAndView("adminManagerTiles.do","getAllMember", listMemberDTO);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return mv;
	}
	//기업 탈퇴 취소
	@RequestMapping("adminCompanyReceive.do")
	public ModelAndView adminCompanyReceive(HttpServletRequest request,String id, String choiceMember){
	 
		int page = Integer.parseInt(request.getParameter("page"));
		ModelAndView mv = null;
		String nowTime = util.Utilities.getNow();
		ListCompanyPageDTO listCompanyDTO = null;
		try {
			CompanyDTO mdto = service.getCompanyById(id);
			request.setAttribute("choiceMember", choiceMember);
			mdto.setDelete_date(nowTime);
			mdto.setIs_validate("O");
			service.adminCompanyReceive(mdto);
			listCompanyDTO = service.getCompanyListByPage(page);
			mv = new ModelAndView("adminManagerTiles.do","getAllCompany", listCompanyDTO);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return mv;
	}
	//ID찾기폼
	@RequestMapping("idSearchForm.do")
	public ModelAndView idSearchForm(HttpServletRequest request){
		String choiceMember = request.getParameter("choiceMember");
		
		ModelAndView mv = null;

		 	
		
		if(choiceMember.equals("member")){
			mv = new ModelAndView("memberIdSearchFormTiles.do");
			
		}else if(choiceMember.equals("company")){
			mv = new ModelAndView("companyIdSearchFormTiles.do");
			
		}else if(choiceMember.equals("admin")){
			mv = new ModelAndView("adminIdSearchFormTiles.do");
		}
		
		return mv;
	}
	//비밀번호 찾기폼
	@RequestMapping("passwordSearchForm.do")
	public ModelAndView passwordSearchForm(HttpServletRequest request){
		String choiceMember = request.getParameter("choiceMember");
		ModelAndView mv = null;
		if(choiceMember.equals("member")){
			mv = new ModelAndView("memberPasswordSearchFormTiles.do");
			
		}else if(choiceMember.equals("company")){
			mv = new ModelAndView("companyPasswordSearchFormTiles.do");
			
		}else if(choiceMember.equals("admin")){
			mv = new ModelAndView("adminPasswordSearchFormTiles.do");
		}

		return mv;
	}
	//회원ID찾기 결과
	@RequestMapping("memberIdSearchResult.do")
	public ModelAndView memberIdSearchResult(MemberDTO mdto){
		 
		String id = service.memberIdSearchResult(mdto);
		return new ModelAndView("memberIdSearchResultTiles.do","id",id);
	}
	//회원Password찾기 결과
	@RequestMapping("memberPasswordSearchResult.do")
	public ModelAndView passwordSearchResult(MemberDTO mdto){
	 
		String password = service.memberPasswordSearchResult(mdto);
		return new ModelAndView("memberPasswordSearchResultTiles.do","password",password);
	}
	//기업ID찾기 결과
	@RequestMapping("companyIdSearchResult.do")
	public ModelAndView companyIdSearchResult(CompanyDTO cdto){
	 
		String id = service.companyIdSearchResult(cdto);
		return new ModelAndView("companyIdSearchResultTiles.do","id",id);
	}
	//기업Password찾기 결과
	@RequestMapping("companyPasswordSearchResult.do")
	public ModelAndView companyPasswordSearchResult(CompanyDTO cdto){
	 
		String password = service.companyPasswordSearchResult(cdto);
		return new ModelAndView("companyPasswordSearchResultTiles.do","password",password);
	}
	//관리자 아이디 조회
	@RequestMapping("adminIdSearchResult.do")
	public ModelAndView adminIdSearchResult(AdminDTO adto){
		
		String id = service.adminIdSearchResult(adto);
		 
		return new ModelAndView("adminIdSearchResultTiles.do","id",id);
	}
	//관리자 Password찾기 결과
	@RequestMapping("adminPasswordSearchResult.do")
	public ModelAndView adminPasswordSearchResult(AdminDTO adto){
		 
		String password = service.adminPasswordSearchResult(adto);
		return new ModelAndView("adminPasswordSearchResultTiles.do","password",password);
	}
	//아이디 검색 index
	@RequestMapping("idSearchIndex.do")
	public ModelAndView idSearchIndex(){
		return new ModelAndView("idSearchIndexTiles.do");
	}
	//password찾기 index
	@RequestMapping("passwordSearchIndex.do")
	public ModelAndView passwordSearchIndex(){
		return new ModelAndView("passwordSearchIndexTiles.do");
	}

	//paging
	@RequestMapping("selectMemberListByPage.do")
	public ModelAndView saleAllListByPaging(HttpServletRequest request){
		ModelAndView mv = null;
		ListMemberPageDTO listMemberDTO = null;
		ListCompanyPageDTO listCompanyDTO = null;
		String choiceMember = request.getParameter("choiceMember");
	 
		int page=1;
		 
		try{
			if(request.getParameter("page")!= null){
				page = Integer.parseInt(request.getParameter("page"));
			}
			else{
				page = 1;
			}
			
			request.setAttribute("choiceMember", choiceMember);
			
			
			if(choiceMember.equals("member")){
			 
			
			listMemberDTO = service.getMemberListByPage(page);
			//신용도 처리(-5이하 : 불량고객, -5~5 : 일반고객, 5이상 : 우량고객, 10이상 : 골드고객)
			for(int i=0;i<listMemberDTO.getList().size();i++){
				if(listMemberDTO.getList().get(i).getCredit_score()<=-5){
					service.updateCredit(listMemberDTO.getList().get(i).getId(),"불량");
					 
				}else if(listMemberDTO.getList().get(i).getCredit_score()<5){
					service.updateCredit(listMemberDTO.getList().get(i).getId(),"일반");
					 
				}else if(listMemberDTO.getList().get(i).getCredit_score()<10){
					service.updateCredit(listMemberDTO.getList().get(i).getId(),"우량");
					 
				}else if(listMemberDTO.getList().get(i).getCredit_score()>=10){
					service.updateCredit(listMemberDTO.getList().get(i).getId(),"골드");
				 
				}
			}
			 
			mv = new ModelAndView("adminManagerTiles.do","getAllMember",listMemberDTO);
			}else if(choiceMember.equals("company")){
				
			listCompanyDTO = service.getCompanyListByPage(page);
			//신용도 처리(-5이하 : 불량고객, -5~5 : 일반고객, 5이상 : 우량고객, 10이상 : 골드고객)
			for(int i=0;i<listCompanyDTO.getList().size();i++){
				if(listCompanyDTO.getList().get(i).getCredit_score()<=-5){
					service.updateCreditCompany(listCompanyDTO.getList().get(i).getId(),"불량");
					 
				}else if(listCompanyDTO.getList().get(i).getCredit_score()<5){
					service.updateCreditCompany(listCompanyDTO.getList().get(i).getId(),"일반");
					 
				}else if(listCompanyDTO.getList().get(i).getCredit_score()<10){
					service.updateCreditCompany(listCompanyDTO.getList().get(i).getId(),"우량");
				 
				}else if(listCompanyDTO.getList().get(i).getCredit_score()>=10){
					service.updateCreditCompany(listCompanyDTO.getList().get(i).getId(),"골드");
				 
				}
			}
		 
			mv = new ModelAndView("adminManagerTiles.do","getAllCompany",listCompanyDTO);
				
			} 
			request.setAttribute("page", page);
		}
		catch(Exception e){
			e.printStackTrace();
			mv = new ModelAndView("error.do","error_message",e.getMessage());
		}
		
		return mv;
	}
	@RequestMapping("event.do")
	public ModelAndView event(HttpServletRequest request,HttpSession session, String number1,String number2, String number3, String number4, String number5, String number6){
		 
		 
		TreeSet lotto = new TreeSet();
		for (int i = 0; i < 1; i++) {
			
			while (true) {

				lotto.add((int) (Math.random() * 45 + 1));

				if (lotto.size() == 6) {

					break;
				}
			}
			 
		}
		 
//		Iterator it = lotto.iterator();
//		int cnt=0;
//		while(it.hasNext()){
//			String obj = (String)it.next();
//			if(obj.equals(number1)){
//				cnt++;
//			}
//		}
		int cnt = 0;
		 
		if(lotto.contains(Integer.parseInt(number1))){
			cnt++;
		}
		if(lotto.contains(Integer.parseInt(number2))){
			cnt++;
		}
		if(lotto.contains(Integer.parseInt(number3))){
			cnt++;
		}
		if(lotto.contains(Integer.parseInt(number4))){
			cnt++;
		}
		if(lotto.contains(Integer.parseInt(number5))){
			cnt++;
		}
		if(lotto.contains(Integer.parseInt(number6))){
			cnt++;
		}
	 
		request.setAttribute("dapCnt", cnt);
		HashMap<String, String> lottoInput = new HashMap<String, String>();
		lottoInput.put("number1", number1);
		lottoInput.put("number2", number2);
		lottoInput.put("number3", number3);
		lottoInput.put("number4", number4);
		lottoInput.put("number5", number5);
		lottoInput.put("number6", number6);
		
		MemberDTO mdto = (MemberDTO) session.getAttribute("memberDTO");
		CompanyDTO cdto = (CompanyDTO) session.getAttribute("companyDTO");
		if(mdto!=null){
			mdto.setMileage(mdto.getMileage()+cnt);
			service.memberPointAdd(mdto.getMileage(),mdto.getId());
		}
		if(cdto!=null){
			cdto.setMileage(cdto.getMileage()+cnt);
			service.companyPointAdd(cdto.getMileage(),cdto.getId());
		}
		request.setAttribute("lottoInput", lottoInput);
		return new ModelAndView("lottoTiles.do","lotto",lotto);
	}
}
